package com.example.grpcclient.controller;

import com.example.proto.NewsProto;
import com.example.proto.NewsServiceGrpc;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class NewsController {

    @GrpcClient("news-client")
    private NewsServiceGrpc.NewsServiceBlockingStub newsStb;

    @RequestMapping("/say")
    public String say(String name) {
        NewsProto.StringRequest stringRequest = NewsProto.StringRequest.newBuilder()
                .setName(name)
                .build();
        System.out.println("收到web请求：" + name);

        // grpc调用
        NewsProto.StringResponse stringResponse = newsStb.hello(stringRequest);
        return stringResponse.getResult();
    }
}
